﻿using QG.JobBack.BLL.IService;
using QG.JobBack.DAL;
using QH.JobBack.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace QG.JobBack.BLL.Service
{
    public class LogsService : BaseRepository<LogsInfo>, ILogsService
    {

        /// <summary>
        /// 查询所有日志（table显示）
        /// </summary>
        /// <returns></returns>
        public List<LogsBase> QueryLogsAll(Nullable<int> RoidId, Nullable<DateTime> BeginTime)
        {
            


            using (var db = new qgpingEntities())
            {
                var str = from a in db.Logsinfo
                          join b in db.Admininfo
                          on a.AdminId equals b.AdminId
                          join c in db.Admin_roleinfo
                          on b.AdminId equals c.AdminId
                          join d in db.RoleInfo
                          on c.RoleId equals d.RoleId
                          select new LogsBase()
                          {
                              RoidId=d.RoleId,
                              LogId = a.LogId,
                              AdminId = a.AdminId,
                              AdminName = b.AdminName,
                              Level = d.RoleName,
                              Status = a.Status,
                              Operation =a.Operation,
                              BeginTime=a.BeginTime,
                              EndTime=a.EndTime
                          };
                 var tolists= str.ToList();

                if (RoidId==0)
                {
                    return tolists.ToList<LogsBase>();
                }
                if (!string.IsNullOrEmpty(RoidId.ToString()))
                {
                    tolists = tolists.Where(d => d.RoidId == RoidId).ToList();
                }
                if (!string.IsNullOrEmpty(BeginTime.ToString()))
                {
                    tolists = tolists.Where(a => a.BeginTime.ToString("yyyy-MM-dd") == BeginTime.Value.ToString("yyyy-MM-dd")).ToList();
                }

                return tolists.ToList<LogsBase>();
            }
        }
    }
}
